﻿using BPMN.Application.IService;
using BPMN.Domain;
using BPMN.Domain.Entity.User;
using BPMN.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using BPMN.DomianShare;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using BPMN.Application.Contracts.DTO.Request.UserInfo;
using BPMN.Application.Contracts.DTO.Request.Role;
using BPMN.Application.Contracts.DTO.Response.Permission;
using BPMN.Application.Contracts.DTO.Response;
using System.Security.Cryptography;
using BPMN.Application.Contracts.DTO.Request.Menu;

namespace BPMN.Application.Service
{
    public class MenuAppService : AppServiceBase<Menu>, IMenuAppService
    {
        private readonly IRepositoryBase<Menu> reMenu;
        private readonly IMapper mapper;


        public MenuAppService(IRepositoryBase<Menu> _reMenu, IMapper mapper) : base(_reMenu)
        {
            this.reMenu = _reMenu;
            this.mapper = mapper;
        }

        public async Task<ResultResponseDto<int>> AddMenu(MenuShowDto menu)
        {
            var obj = mapper.Map<Menu>(menu);
            int n = await reMenu.Add(obj);
            if (n > 0)
            {
                return new ResultResponseDto<int>();
            }
            else
            {
                return new ResultResponseDto<int>(ResultCode.Fail, "修改失败");
            }
        }

        public async Task<ResultResponseDto<MenuShowDto>> GetMenuById(int Id)
        {
            var slist = await reMenu.Get(Id);

            return new ResultResponseDto<MenuShowDto>()
            {
                Code = ResultCode.Ok,
                ErrorInfo = "获取成功",
                Data = mapper.Map<MenuShowDto>(slist)


            };
        }

        public async Task<ResultResponseDto<int>> UpdateMenu(MenuShowDto entity)
        {
            

            var obj = mapper.Map<Menu>(entity);
            int n = await reMenu.Update(obj);
            if (n > 0)
            {
                return new ResultResponseDto<int>();
            }
            else
            {
                return new ResultResponseDto<int>(ResultCode.Fail, "修改失败");
            }
        }
    }
}

